<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
    <title>代理商管理系统</title>
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/color.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/demo.css" />
    <script src="${ctx}/statics/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body class="easyui-layout" >
    <form method="post" id="update" >
        <div data-options="region:'north',split:false" style="height:150px;background:#eee;padding:10px 20px 10px 20px">
            <div style="padding-left:10px;margin-bottom:10px"><h5 style="margin:0">基本信息</h5></div>
            <div style="border:1px solid lightgrey;padding-left:10px">
                <p>
                    <span style="width:60px;text-align:justify;display:inline-block">
                        企业名称:
                    </span>
                    <input class="easyui-textbox" type="text" name="customName" style="width:150px;"
                            data-options="required:true,missingMessage:'必填'" />
                    <span style="margin-left:150px;width:60px;text-align:justify;display:inline-block">企业类型:</span>
                    <input name="customType" style="width:150px" />
                    <input type="hidden" name="customTypeName"  />
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        企业主页:
                    </span>
                    <input class="easyui-textbox" type="text" name="siteUrl" style="width:150px;"
                            data-options="required:true,missingMessage:'必填'" />
                    <span style="margin-left:150px;width:60px;text-align:justify;display:inline-block">
                        状态:
                    </span>
                    <select class="easyui-combobox" name="customStatus" style="width:150px;">
                        <option value='true' selected >启用</option>
                        <option value='false' >不启用</option>
                    </select>
                </p>
            </div>
        </div>
        <div data-options="region:'south',split:false" style="height:130px;background:#eee;padding:10px">
            <p style="text-align:center;margin-top:70px">
                <a href="javascript:void(0)" class="easyui-linkbutton c6"
                   onclick="submitForm()" style="width:60px;margin-right:10px;">保存</a>
                <a href="javascript:void(0)" class="easyui-linkbutton c6"
                   onclick="cancel()" style="width:60px;">返回</a>
                <input type="hidden" value="${requestScope.customId}" name="id" />
            </p>
        </div>
        <div data-options="region:'center',split:false" style="background:#eee;padding:10px 20px 10px 20px">
            <div style="padding-left:10px;margin-bottom:10px"><h5 style="margin:0">门户信息</h5></div>
            <div style="border:1px solid lightgrey;padding-left:10px">
                <p>
                    <span style="width:60px;text-align:justify;display:inline-block">
                        法人代表:
                    </span>
                    <input class="easyui-textbox" type="text" name="bossName" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                    <span style="margin-left:150px;width:60px;text-align:justify;display:inline-block">
                        注册日期:
                    </span>
                    <input type="text" class="easyui-datetimebox" name="regTime" required="required" style="width:150px;" readonly />
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        证件类型:
                    </span>
                    <input name="cardType" style="width:150px" />
                    <input type="hidden" name="cardTypeName" />
                    <span style="margin-left:150px;width:60px;text-align:justify;display:inline-block">
                        证件号码:
                    </span>
                    <input class="easyui-textbox" type="text" name="cardNum" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        公司电话:
                    </span>
                    <input class="easyui-textbox" type="text" name="companyTel" style="width:150px;" />
                    <span style="margin-left:150px;width:60px;text-align:justify;display:inline-block">
                        公司传真:
                    </span>
                    <input class="easyui-textbox" type="text" name="companyFax" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        国家:
                    </span>
                    <input class="easyui-textbox" type="text" name="country" style="width:150px;" />
                    <span style="margin-left:150px;width:60px;text-align:justify;display:inline-block">
                        公司地址:
                    </span>
                    <input class="easyui-textbox" type="text" name="companyAddress" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                </p>
                <p style="margin-top:20px">
                    <span>
                        省/地区:
                    </span>
                    <input name="province" style="width:150px" />
                    <span style="margin-left:45px;">
                        城市:
                    </span>
                    <input name="city" style="width:150px" />
                    <span style="margin-left:45px;">
                        区:
                    </span>
                    <input name="area" style="width:150px" />
                </p>
                <p>
                    <span style="display:block">备注</span>
                    <textarea name="memo" rows="5" cols="100"></textarea>
                </p>
            </div>
        </div>
    </form>

    <script>

        $(
            function ()
            {
                //页面加载设置企业类型选项
                $("[name=customType]").combobox(
                    {
                        url:'${ctx}/do/comboboxJsonStr',
                        queryParams:{"action":"customType"},
                        valueField:'configTypeValue',
                        textField:'configValue',
                        editable: false,
                        onSelect: function( rec )
                        {
                            $("[name=customTypeName]").val( rec.configValue );
                        }
                    });
                //页面加载设置证件类型选项
                $("[name=cardType]").combobox(
                    {
                        url:'${ctx}/do/comboboxJsonStr',
                        queryParams:{"action":"cardType"},
                        valueField:'configTypeValue',
                        textField:'configValue',
                        editable: false,
                        onSelect: function( rec )
                        {
                            $("[name=cardTypeName]").val( rec.configValue );
                        }
                    });
                //设置地区选项combobox
                var areaCombobox = $("[name=area]").combobox(
                    {
                        disable:true,
                        valueField:'areaId',
                        textField:'area',
                        editable: false
                    });

                //设置城市选项combobox
                var cityCombobox = $("[name=city]").combobox(
                    {
                        disable:true,
                        valueField:'cityId',
                        textField:'city',
                        editable: false,
                        //选择城市时级联地区
                        onSelect: function( city )
                        {
                            //alert( city );
                            areaCombobox.combobox(
                                {
                                    disable:false,
                                    url:'${ctx}/do/comboboxJsonStr',
                                    queryParams:{"action":"area","cityId":city.cityId},
                                    valueField:'areaId',
                                    textField:'area',
                                    editable: false
                                }).combobox('clear');

                        }
                    });

                //设置省份选择combobox
                var provinceCombobox = $("[name=province]").combobox(
                        {
                            url:'${ctx}/do/comboboxJsonStr',
                            queryParams:{"action":"province"},
                            valueField:'provinceId',
                            textField:'province',
                            editable: false,
                            //选择省份时级联城市
                            onSelect: function( province )
                            {
                                //alert(province.provinceId);
                                cityCombobox.combobox(
                                    {
                                        disable:false,
                                        url:'${ctx}/do/comboboxJsonStr',
                                        queryParams:{"action":"city","provinceId":province.provinceId},
                                        valueField:'cityId',
                                        textField:'city',
                                        editable: false
                                        //选择城市时级联地区
                                    }).combobox('clear');
                            }
                        });

                //首先发送查询该用户
                var customId = parseInt( ${requestScope.customId} );
                //发送请求查询客户信息
                $.ajax(
                    {
                        type:"POST",
                        url:"${ctx}/do/selectCustom",
                        data:{"customId":customId},
                        dataType:"json",
                        success:function ( json )
                        {
                            //根据查询结果设置表单数据
                            $("#update").form( 'load' ,
                                {
                                    customName:json.customName,
                                    siteUrl:json.siteUrl,
                                    bossName:json.bossName,
                                    regTime:json.regDatetime,
                                    cardNum:json.cardNum,
                                    companyTel:json.companyTel,
                                    companyFax:json.companyFax,
                                    country:json.country,
                                    companyAddress:json.companyAddress,
                                    memo:json.memo,
                                    customStatus:json.customStatus + "",
                                    customType:json.customType,
                                    cardType:json.cardType,
                                    customTypeName:json.customTypeName,
                                    cardTypeName:json.cardTypeName
                                });
                            //根据查询结果设置省市区三级联动显示结果
                            provinceCombobox.combobox('select',json.province );
                            areaCombobox.combobox(
                                {
                                    disable:false,
                                    url:'${ctx}/do/comboboxJsonStr',
                                    queryParams:{"action":"area","cityId":json.city},
                                    valueField:'areaId',
                                    textField:'area',
                                    editable: false
                                }
                            ).combobox('select',json.area);
                            cityCombobox.combobox('select',json.city);
                        }
                    }
                )
            }
        );

        //点击保存按钮提交表单
        function submitForm()
        {
            //设置表单请求
            $("#update").form(
                {
                    url:"${ctx}/do/updateCustom",
                    //提交成功后处理返回值
                    success:function(data)
                    {
                        //注意需要将返回值转换为json
                        var json = JSON.parse(data);
                        //alert(json.message);
                        if( json.message == 1 )
                        {
                            $.messager.alert('更新操作','更新成功','info',
                                function(result)
                                {
                                    window.location.href = "${ctx}/do/toAgentCustomManagePage";
                                });
                        }
                        else
                        {
                            $.messager.alert('更新操作','更新失败','info',
                                function()
                                {
                                    window.location.href = "${ctx}/do/toAgentCustomManagePage";
                                });
                        }
                    }
                });
            //提交表单
            $("#update").submit();
        }

        //点击取消按钮返回客户管理页面
        function cancel()
        {
            window.location.href = "${ctx}/do/toAgentCustomManagePage";
        }
    </script>
</body>
</html>
